#include <bits/stdc++.h>

using namespace std;

int n, ans;

int dfs(const vector<list<pair<int, int>>> &adj_list, int u, int father)
{
    int dist = 0;
    int d1 = 0, d2 = 0;
    for (auto &l : adj_list[u])
    {
        if (l.first == father)
        {
            continue;
        }
        int d = dfs(adj_list,l.first, u) + l.second;
        dist = max(dist, d);

        if (d >= d1)
        {
            d2 = d1;
            d1 = d;
        }
        else if (d > d2)
        {
            d2 = d;
        }
    }

    ans = max(ans, d1 + d2);
    return dist;
}

int main()
{
    vector<list<pair<int, int>>> adj_list;
    cin >> n;
    adj_list.resize(n + 1);
    for (int i = 0; i < n - 1; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj_list[a].push_front({b, c});
        adj_list[b].push_front({a, c});
    }
    dfs(adj_list, 1, -1);
    cout << ans;
    return 0;
}